package com.server.view;

import com.server.model.ServerAccepter;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 */

/*
服务器端控制界面,可以完成启动服务器,关闭服务器
看到在线用户,管理和监控用户
 */

public class ServerFrame extends JFrame implements ActionListener {
    public static void main(String[] args) {
        new ServerFrame();
    }
    JPanel jp1;
    JButton jb1;
    ServerAccepter serverAccepter;
    Thread thread;
    public ServerFrame() {
        jp1 = new JPanel();
        jb1 = new JButton("启动服务器");
        jb1.addActionListener(this);
        jp1.add(jb1);
        this.add(jp1);
        this.setSize(250, 80);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("服务器");
        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
            if(jb1.getText().equals("启动服务器")){
                jb1.setText("关闭服务器");
                thread = new Thread(() -> serverAccepter = new ServerAccepter());
                thread.start();
            }else{
                thread.stop();
                this.dispose();
                System.exit(0);
            }
    }
}
